package com.xunyun.kotlinwc.utils

import android.annotation.SuppressLint
import android.content.Context
import android.widget.Toast
import es.dmoral.toasty.Toasty

/**
 * @author gl
 * @date 2021/9/9
 * @desc
 */
@SuppressLint("StaticFieldLeak")
object ToastUtils {

    private var context: Context? = null

    /**
     * 在Application中初始化ToastUtils.init(this)
     * @param context
     */
    fun init(context: Context) {
       this.context = context.applicationContext
    }

    /**
     * 普通提示消息
     * @param msg
     */
    fun showInfo(msg: String?) {
        context?.let {
            if (msg != null) {
                Toasty.info(it,msg,Toast.LENGTH_LONG,true).show()
            }
        }

    }


    /**
     * 成功提示消息
     * @param msg
     */
    fun showSuccess(msg: String?) {
        context?.let {
            if (msg != null) {
                Toasty.success(it,msg,Toast.LENGTH_LONG,true).show()
            }
        }
    }

    /**
     * 错误提示消息
     * @param msg
     */
    fun showError(msg: String?) {
        context?.let {
            if (msg != null) {
                Toasty.error(it,msg,Toast.LENGTH_LONG,true).show()
            }
        }
    }
}